package pers.amos.edu.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pers.amos.edu.common.GlobalResult;
import pers.amos.edu.pojo.CollectionSchool;
import pers.amos.edu.service.CollectionSchoolService;

import java.util.List;

/**
 * @author amos wong
 * @create 2020-02-02 18:19
 */

@Api(tags = "收藏学校的接口")
@RestController
@RequestMapping("/edu/collection")
public class CollectionSchoolController {

    @Autowired
    private CollectionSchoolService schoolService;

    /**
     * 收藏学校的接口
     *
     * @param openId   微信用户的openId
     * @param schoolId 学校的id
     * @return
     */
    @ApiOperation("收藏学校的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "openId"),
            @ApiImplicitParam(name = "schoolId", value = "学校id")})
    @PostMapping("/school/{openId}")
    public GlobalResult addCollection(@PathVariable String openId, Integer schoolId) {
        return schoolService.addCollection(openId, schoolId);
    }

    /**
     * 取消收藏学校的接口
     *
     * @param openId   微信用户的openId
     * @param schoolId 学校的id
     * @return
     */
    @ApiOperation("取消收藏学校的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "openId"),
            @ApiImplicitParam(name = "schoolId", value = "学校id")})
    @DeleteMapping("/school/{openId}")
    public GlobalResult deleteCollection(@PathVariable String openId, Integer schoolId) {
        return schoolService.cancelCollection(openId, schoolId);
    }

    /**
     * 查询用户所收藏的学校
     *
     * @param openId 微信用户的openId
     * @return
     */
    @ApiOperation("查询某用户收藏的学校列表")
    @ApiImplicitParam(name = "openId", value = "openId")
    @GetMapping("/school/{openId}")
    public ResponseEntity<List<CollectionSchool>> getCollectionByPage(@PathVariable String openId) {
        List<CollectionSchool> list = schoolService.getSchoolCollection(openId);
        return ResponseEntity.ok().body(list);
    }
}